#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        int hash[128] = { 0 };
        int n = s.size();
        int len = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            hash[s[right]]++;
            while (hash[s[right]] > 1)
            {
                hash[s[left]]--;
                left++;
            }
            len = max(len, right - left + 1);
        }
        return len;
    }
};

int main()
{
    Solution S;
    string s = { "abcdebad" };
    int ret = S.lengthOfLongestSubstring(s);

    cout << ret << endl;

}
